import 'package:flutter/material.dart';
import 'package:dio/dio.dart';
import 'dart:convert';

void main() => runApp(HttpTestPage());

class HttpTestPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'xixix',
      home: HomePage(),
    );
  }
}

class HomePage  extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  var _list = [];

  void handleRequest() async {
    Dio dio = new Dio();
    try {
      var response = await dio.get("http://rap2api.taobao.org/app/mock/120100/assist/knowledge/front/displayKnowledge");
//      var jsonResponse = json.decode(response.data);
      setState(() {
        _list = response.data['result']['data'];
      });
    }catch(e) {
      print(e);
    }
  }

  getList() {
    return _list.map((item) {
      Text(item['id']);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('头部'),),
      body: Column(
        children: <Widget>[
          RaisedButton(
            onPressed: () => handleRequest(),
            child: Text('发请求'),
          ),
//          ListView(
//            children: getList(),
//          )
        ],
      ),
    );
  }
}